// 防抖函数
export function debounce(func, delay) {
  let timer = null
  return function(...args) {
    if (timer) clearTimeout(timer)
    timer = setTimeout(() => {
      func.apply(this, args)
    }, delay)
  }
}
// 格式化时间
export function dateFormat(data, fmt = "yyyy-mm-dd HH:ii:ss") {

  const fdate = new Date(data)
  let o = {
    'y+': fdate.getFullYear().toString(),
    'm+': (fdate.getMonth() + 1).toString(),
    'd+': fdate.getDate().toString(),
    'H+': fdate.getHours().toString(),
    'i+': fdate.getMinutes().toString(),
    's+': fdate.getSeconds().toString()
  }


  for (let k in o) {
    if (new RegExp(`(${k})`, "i").test(fmt)) {
      let str = o[k]
      fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? str : str.padStart('2', '0'))
    }

  }
  return fmt
}
